{
数据结构 解题报告：
http://git.oschina.net/et0662/sznoi-Data_Structure
}

type
	pnode=^node;
	node=record
		data:char;
		left:pnode;
		right:pnode;
		end;
	tree=node;
	ptree=pnode;
var
	a,b:string;

{恢复树}
function makeTree(i,j,m,n:integer):ptree;
var
	p:pnode;
	c:char;
	x,y:integer;
begin
	if(i>j) or (m>n) then
		p:=nil
	else
	begin
		c:=a[i];
		for x:=m to n do
		begin
			if(c=b[x])then
				break;
		end;
		x:=x-m; {左子树的结点数}
		y:=n-x; {右子树的结点数}

		new(p);
		p^.data:=c;
	
		if(x>0)then
			p^.left:=makeTree(i+1,i+x,m,m+x-1)
		else
			p^.left:=nil;
		if(y>0)then
			p^.right:=makeTree(i+x+1,j,m+x+1,n)
		else
			p^.right:=nil;
	end;
	makeTree:=p;
end;


procedure rpt(t:ptree);
begin
	if(t<>nil)then
	begin
		rpt(t^.left);
		rpt(t^.right);
		write(t^.data);
	end;
end;

procedure emptyTree(t:ptree);
begin
	if(t<>nil)then
	begin
		emptyTree(t^.left);
		emptyTree(t^.right);
		dispose(t);
	end;
end;

var
	len:integer;
	t:ptree;
begin
	readln(a);
	readln(b);
	len:=length(a);
	t:=makeTree(1,len,1,len);
	rpt(t);
	emptyTree(t);
end.
